﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/MasterHalfColum.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.ViewModels.UserPermissionViewModels>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Danh sách quyền người dùng
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContentLeft" runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
	<script src="/Scripts/jquery.cookie.js" type="text/javascript"></script>
	<script src="/Scripts/jquery.treeview.js" type="text/javascript"></script>
    <script type="text/javascript" src="/Scripts/demo.js"></script>
<script type="text/javascript">


    function SaveStatus(dropDownList, id) {
        var selectedReport = dropDownList.options[dropDownList.selectedIndex];
        var selects = selectedReport.value;
        actionChangeStatus(selects, id);
    }
    function actionChangeStatus(values, id) {
        var url = '<%=Url.Action("ChangeStatusUserPermission","User")%>' + '/' + id + '/' + values;
        $.getJSON(url, function (outStr) {
            $('#statusID' + id).val(outStr);
        });
    }    

</script> 
     <% using (Html.BeginForm("ListUserPermissions", "User"))
        {%>
   <div class="box ">
		<h2 class="box-header"> Danh sách quyền người dùng	</h2>
		<div class="box-content">
                     
                    <div id="grid">     
                                <div style="float:right; margin:10px;"> 
                                   <%= Html.ActionLink("Tạo quyền người dùng mới", "CreateUserPermission", null, new { @class = "button themed" })%>
                                 </div>		               
                                <table class="display" cellpadding="0" cellspacing="0" border="0" style="width:100%" >
                                <thead>
					                <tr>
						                                                        					               
						                <th>
							                <a href="#" class="<%= UserController.GetGridThClass(ViewData, "PerName") %>" 
										                onclick="<%= UserController.GetGridThOnClick(ViewData, "PerName")%>">
								                Tên nhóm quyền</a>
						                </th>
						
                                        <th>
                                            Trạng thái                                        
                                        </th>
                                 						                
                                        <th></th>
                                        <th></th>
					                </tr>
                                    <tr>
                                        <td>
                                            <%=Html.TextBoxFor(m => m.PerName, new { @class = "form-field hafl", @maxlength = "100" })%>
                                        </td>
                                                                           
                                        <td>
                                           <%
                                                List<SelectListItem> statusSearch = new List<SelectListItem>();
                                                statusSearch.AddRange(new SelectListItem[] { 
                                                new SelectListItem{ Text = "Kích hoạt", Value = "1" },
                                                new SelectListItem{ Text = "Không kích hoạt", Value = "0" }
                                                });
                                                %>

                                                <%=Html.DropDownListFor(m => m.PerStatus, statusSearch)%> 
                                        </td>
                                                                                                                      
                                        <td>
                                            
                                        </td>

                                        <td>
                                            
                                            <input type="submit" value="Tìm kiếm" class="button themed"/>
                                           <%-- <%= Html.ActionLink("Tạo quyền người dùng mới", "CreateUserPermission", null, new { @class = "button themed" })%>--%>
                                        </td>
                                    </tr>
                                </thead>
                                <% if (Model.UserPermissionItems.Count() == 0) { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="5">
                                                Không tìm thấy
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% } else { %>
                                <tbody>
					                <% foreach (var item in Model.UserPermissionItems)
                        { %>
				                        
						                <tr>						                
                                            
							                <td>
								                <%= Html.Encode(item.PerName) %>
							                </td>														               
											
                                            <td>
                                                <%
                                                    bool newStatus=false;
                                                    if (item.PerStatus == 0)
                                                    {
                                                        newStatus=true;
                                                    }
                                                    else if (item.PerStatus == 1)
                                                    {
                                                        newStatus=false;
                                                    }
                                                %>
                                                <%
                                                List<SelectListItem> statusDrop = new List<SelectListItem>();
                                                statusDrop.AddRange(new SelectListItem[] { 
                                                new SelectListItem{Selected=newStatus, Text = "Kích hoạt", Value = "1" },
                                                new SelectListItem{Selected=newStatus, Text = "Không kích hoạt", Value = "0" }
                                                });
                                                %>
                                              
                                               <%= Html.DropDownList("statusID" + item.PerID, statusDrop, new { onchange = "SaveStatus(this," + item.PerID + ")" })%>
                                            </td>

                                            
                                            <td>
                                            
                                            </td>
                                            <td> 
                                                <%=Html.ActionLink("Phân Module", "AssignModule", new { id = item.PerID })%> | 
								                <%--<%= Html.ActionLink("Cập nhật", "EditUserPermission", new { id = item.PerID })%> --%>
                                                 <span class="button white"> <%= Html.ActionLink(" ", "EditUserPermission", new { id = item.PerID }, new { @class = "icon_single edit", style = "color:#f7a468;" })%></span>	<!--cap nhat-->	| 								                
							                
                                                <%
                                                    string returnUrl = Request.Url.ToString();
                                                 %>
                                               <%-- <%= Html.ActionLink("Xóa", "DeleteUserPermission", new { id = item.PerID, returnUrl = returnUrl }, new { onclick = "return confirm('Delete Permission:" + item.PerName + " ?');" })%>--%>
                                                <span class="button white"><%= Html.ActionLink(" ", "DeleteUserPermission", new { id = item.PerID, returnUrl = returnUrl }, new { @class = "icon_single cancel", style = "color:#cc0000;", onclick = "return confirm('Bạn thực sự muốn xóa?');" })%></span>

                                            </td>
						                </tr>
                                            <script type="text/javascript">
                                                
                                            </script>
                                            
                                             
					                <% } %>
					            </tbody>
                                 <% } %>
				                </table>   
                                 	          
			                <!-- data -->
                                <% if (Model.UserPermissionItems.Count() > 0)
                                   { %>
			                       <% Html.RenderPartial("~/Views/Commont/Paging.ascx"); %>
		                        <% } %>
		                        
	                </div>  <!-- grid -->	
                
               
	     </div>
	</div>
    <% } %>   

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContentRight" runat="server"> 
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
	<script src="/Scripts/jquery.cookie.js" type="text/javascript"></script>
	<script src="/Scripts/jquery.treeview.js" type="text/javascript"></script>
    <script type="text/javascript" src="/Scripts/demo.js"></script>
    <div class="box ">
		<h2 class="box-header">	 </h2>
		<div class="box-content">
			    <%=ViewData["ListPermission"]%>
	    </div>
	</div>
   
</asp:Content>